<template>
  <el-card shadow="hover" @click="sayHi">
    <div class="content">
      <div class="left">
        <p :style="{ color: depColor }">{{  name  }}</p>
        <p><span>{{  price  }}</span> RMB</p>
      </div>
      <div class="right">
        <img :src="imgUrl" alt="">
      </div>
    </div>
    <div class="subtitle">
      <div class="department" :style="{ backgroundColor: depColor }"> {{  department  }}</div>
      <div class=" description">{{  description  }}</div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { defineProps, h } from 'vue'
import { ElNotification } from 'element-plus'
const prop = defineProps(['cardInfo'])
const { name, price, imgUrl, department, depColor, description } = prop.cardInfo

function sayHi() {
  const index = Math.floor(Math.random() * 4)
  const positionMap = ['bottom-left', 'bottom-right', 'top-left', 'top-right']
  const position: any = positionMap[index]
  ElNotification({
    title: name,
    message: h('i', { style: `color: ${depColor}` }, `${name}朝你打招呼`),
    duration: 2500,
    position
  })
}
</script>

<style scoped lang="less">
.el-card {
  margin: 10px;

  .content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100px;

    .left {
      p {
        margin: 10px 0;
        color: #888;
        font-weight: 600;
      }

      span {
        color: #555;
        font-weight: 800;
        font-size: larger;
      }
    }

    .right {
      box-shadow: 0 0 5px #ccc;
      height: 100px;
      width: 100px;
      margin: 5px;
      border-radius: 10px;
      overflow: hidden;

      img {
        width: 100%;
      }
    }
  }

  .subtitle {
    display: flex;
    line-height: 25px;
    margin-top: 5px;
    font-size: 14px;

    .department {
      height: 25px;
      width: 60px;
      // background-color: orange;
      color: #fff;
      text-align: center;
      border-radius: 5px;
    }

    .description {
      margin-left: 20px;
      color: #999;
    }
  }
}
</style>